<template>
	<view class="box">
		<u-navbar title="修改推荐码" :fixed="true" :placeholder="true" :safeAreaInsetTop="true" :autoBack="false"
			leftIconColor="#fff" titleStyle="color:#fff" bgColor="#211E38" 
			@leftClick="leftClick"></u-navbar>
		
		<view class="tit">
			
		</view>
		<view class="ipt_wrap">
			<input type="text" v-model.trim="invitecode" placeholder="请输入推荐码" />
		</view>

		<view class="btn" @click="submit">
			确定
		</view>
	</view>

</template>

<script>
	import {
		updateInviteCode
	} from "../../api/setting.js"
	export default {
		data() {
			return {
				invitecode:"",
				rule:""
			}
		},
		onLoad() {
		
		},
		onShow() {
		

		},
		methods: {
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			},
			right(){
				uni.navigateTo({
					url:"/pagesMy/exchange/exchangelist"
				})
			},
			submit(){
				if(!this.invitecode){
					uni.$u.toast('请输入推荐码')
					return;
				}
				updateInviteCode({
					invite_code:this.invitecode
				}).then(res=>{
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack()
						},1500)
					}
					uni.$u.toast(res.msg)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@font-face {
		font-family: 'iconfont';
		src: url("~@/iconfont/almm.ttf");
	}

	.box {
		width: 750rpx;
		height: 100vh;
		background-color: #211E38;
	}


	/deep/ .u-navbar__content__right__text {
		color: #FFFFFF;
	}
	.tit{
		width: 600rpx;
		margin: 0 auto;
		font-weight: 400;
		font-size: 28rpx;
		color: #FFFFFF;
		margin-top: 50rpx;
	}
	.ipt_wrap{
		width: 600rpx;
		height: 80rpx;
		background: #3C2F65;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		>input{
			width: 560rpx;
			height: 80rpx;
			background: #3C2F65;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			color: #fff;
			padding-left: 40rpx;
		}
	}
	.rule{
		width: 600rpx;
		margin: 0 auto;
		height: 400rpx;
		margin-top: 20rpx;
	}
	.btn{
		width: 420rpx;
		height: 88rpx;
		background: linear-gradient( 274deg, #0014FF 0%, #8020EF 50%, #FF2CDF 100%);
		border-radius: 520rpx 520rpx 520rpx 520rpx;
		margin: 0 auto;
		margin-top: 50rpx;
		font-weight: 400;
		font-size: 36rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 88rpx;
	}
</style>